package com.study.portal.util;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Properties;

import org.apache.log4j.Logger;

public class InitConfig {
	public static final String basePath;
	public static final String baseTitle;
	public static final String loginPath;
	static{
		Properties properties = readProperties("init.properties");
		basePath = properties.getProperty("basePath");
		String title = properties.getProperty("baseTitle");
		loginPath = properties.getProperty("loginPath");
		
		try {
			title =	new String(title.getBytes("ISO-8859-1"),"UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		baseTitle = title;
		
		if(null==loginPath || null==baseTitle || null==basePath){
			Logger.getLogger(InitConfig.class).error("InitConfig 初始化失败.....",new Throwable("InitConfig 初始化失败....."));
			System.exit(1);
		}
		Logger.getLogger(InitConfig.class).debug("InitConfig 初始化成功...");
	}
	
	public static Properties readProperties(String propertiesPath){
		Properties properties = new Properties();
		try {
			properties.load(InitConfig.class.getClassLoader().getResourceAsStream(propertiesPath));
		} catch (IOException e) {
			e.printStackTrace();
		}
		return properties;
	}
}
